import React, { useState, useEffect } from 'react'

const CountWithStep = () => {
    const [count,setCount] = useState(0)
    const [step,setStep] = useState(0)

    useEffect(()=>{
        const t = setInterval(()=>{
            setCount(v=>v+Number(step))
        },1000)
        return(()=>{
            clearInterval(t)
        })
    },[step])

    return (
        <>
        <h3>自动计数器</h3>
        <div>
            <p>计数：{count}</p>
            <label><input onChange={e=>setStep(e.target.value)}/></label>
        </div>
    </>);
}

export default CountWithStep;
